package com.lyz.dataStructure.JianZhiOffer.listNode1;

import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/7/23 21:34
 *@Description:
 **/
public class DelRepeatListNode {

    public static void main(String[] args) {
        ListNode node = createListNode();
        System.out.println(node);

        System.out.println(del(node));
    }

    public static  ListNode createListNode(){
        ListNode listNode = new ListNode(0);
        ListNode curr = listNode;
        Scanner sc  = new Scanner(System.in);
        for(int i=1;i<5;i++){
            curr.next = new ListNode(i=sc.nextInt());
            curr = curr.next;
        }
        return listNode;
    }

    public static   ListNode del(ListNode pHead){
        if (pHead==null||pHead.next==null) return pHead;
        ListNode next  = pHead.next;
        if(pHead.val == next.val){
            while (next!=null&&pHead.val == next.val)
                next = next.next;
            return  del(next);
        }else {
            pHead.next = del(pHead.next);
            return pHead;
        }
    }


}
